home *** CD-ROM | disk | FTP | other *** search
/ ShareWare OnLine 2 / ShareWare OnLine Volume 2 (CMS Software)(1993).iso / prog / dtbl11.zip / DEMO3.FRM (.txt) < prev    next >
Visual Basic Form  |  1993-05-11  |  12KB  |  224 lines

  1. Form1
  2. !DataTable Example Program - DEMO3
  3. wwwwwwwwwwwwwww
  4. wwwwwwwwwwwwwww
  5. Form1
  6. Customer
  7.     DATATABLE
  8. C:\CUSTOMER
  9. Label1
  10. Name:
  11. CustomerName
  12. Label2
  13. Address:
  14. Address
  15. Label3
  16. City:
  17. Label4
  18. State:
  19. State
  20. Label5
  21. Label6
  22. Phone:
  23. Phone
  24.     TopButton
  25. NextButton
  26. InsertButton
  27. Insert
  28. DeleteButton
  29. Delete
  30. QuitButton
  31. BottomButton
  32. Bottom
  33. PreviousButton
  34. Previous
  35. UpdateButton
  36. Update
  37. ClearButton
  38. Clear
  39. QuitButton_Click
  40. Form_Click
  41.     Form_Load>
  42. Customer
  43.     OpenTableg
  44. Action
  45. CloseTable%
  46. FillForm
  47.     GetRecord
  48.     FieldName
  49. GetField
  50. CustomerName:
  51. Text$
  52. FieldValue
  53. Address
  54. StateW
  55. Phone}
  56.     InsertRecW
  57. PutField
  58. InsertRecord
  59. InsertButton_Click
  60. ClearButton_Click
  61. TopButton_Click
  62. FirstRecord
  63. BottomButton_Click
  64. LastRecord
  65. NextButton_ClickA
  66. NextRecord
  67. PreviousButton_ClickJ
  68. PreviousRecord
  69. DeleteButton_Click
  70. DeleteRecord4
  71.     UpdateRec
  72. UpdateRecord
  73. UpdateButton_Click
  74. Reaction
  75. DisplayError
  76. TheError
  77. CustomerName_Change
  78. CustomerName_LostFocus
  79. SearchMode
  80. SEARCHFIRST
  81. SearchField
  82. TheNameTyped'
  83. database
  84. table
  85.     DataTable
  86.     KeySearch
  87.     SearchKey
  88. Form_Load
  89. Open up the database table
  90. Now fill the form with data 
  91. in the first record.
  92. QuitButton_Click
  93. Close the database table
  94. And quit the program
  95. FillForm
  96. We need to get the current record in the database:
  97. Ok, now lets get the values in the database fields for the
  98. record we just read in::
  99. We need to make a one-to-one relationship between the fields in the database table
  100. and the fields on our Visual Basic Form. We will read in the field values from the
  101. database record and place those values into the .TEXT property of our TEXT controlss
  102. on our Visual Basic form. For each field of interest this is a three-step process:
  103. 1. Specify the name of the database field of interest ---> DataTable.FieldName = "
  104. 2. Get the field value ---> DataTable.Action = GetFieldd
  105. 3. Place the field value in the TEXT control ---> Text1.TEXT = DataTable.FieldValuee
  106. Thats all there is to it!!
  107. You should make a FillForm like subroutine position independent. Notice that the first line of
  108. code in this subroutine reads in the current record. Use other routines to move around
  109. in the table (like the TOP,BOTTOM, NEXT and PREVIOUS buttons in this demo). Making the
  110. routine position independent means that it can be used and re-used at any time to fill inn
  111. your form with information from any record in your database.
  112. We will fill in the form now:o
  113. Address"
  114. State"
  115. Phone"
  116. InsertRec
  117. Here we transfer the information from the Visual Basic Form and insert itt
  118. into the database table.
  119. To do this requires a three-step process for each field in the database table:
  120. 1. Specify the name of the field of interest ---> DataTable.FieldNamee
  121. 2. Specify the field value ---> DataTable.FieldValue = A String valuee
  122. 3. Put the field into the DataTable record ---> DataTable.Action = PutFieldd
  123. We do this for each field in the database table.
  124. When we are finished we INSERT the record into the
  125. database table ---> DataTable.Action = InsertRecordd
  126. Address"
  127. State"
  128. Phone"
  129. InsertButton_Click
  130. ClearButton_Click
  131. This code simply clears the text in all of the Visual Basic form's Text controls..
  132. TopButton_Click
  133. The following code moves to the first record in the data basen
  134. and fills in our form with the information found in that first
  135. record
  136. Moveto the first record in the database
  137. Fill in the form with data
  138. BottomButton_Click
  139. The following code moves to the last record in the data base
  140. and fills in our form with the information found in that last
  141. record
  142. Move to the last recordd
  143. Fill the form 
  144. NextButton_Click
  145. The following code moves to the next record in the database table. If an
  146. error is encountered during the move to the next record an error message is displayed.
  147. The DisplayError subroutine is an example of the structure of a generalized 
  148. DataTable error handling routine. 
  149. Once the repositioning to the next record is successfull, we fill in our form
  150. with information from that record.
  151. Moving to the next record in the databaseu
  152. If an errort
  153. Display the DataTable errore
  154. If no error
  155. Fill in our form with the information in the record.
  156. PreviousButton_Click
  157. The following code moves to the previous record in the database table. If an
  158. error is encountered during the move to the record an error message is displayed.a
  159. The DisplayError subroutine is an example of the structure of a generalizedl
  160. DataTable error handling routine. 
  161. Once the repositioning to the previous record is successfull, we fill in our forma
  162. with information from that record.
  163. Moving to previous records
  164. If an errors
  165. Display the DataTable Errorr
  166. If no error
  167. Fill in our form with info from the record
  168. DeleteButton_Click
  169. This code deletes the current record from the database
  170. The current record after the delete is performed, is the record immediatelyr
  171. following the deleted record. We then fill in our form with info from that
  172. record.n
  173. We will delete the current record.
  174. Now fill in form with the current record.
  175. UpdateRec
  176. Here we transfer the information from the Visual Basic Form and update the current record
  177. in the database table.
  178. To do this requires a three-step process for each field in the database table:
  179. 1. Specify the name of the field of interest ---> DataTable.FieldNames
  180. 2. Specify the field value ---> DataTable.FieldValue = A String values
  181. 3. Put the field into the DataTable record ---> DataTable.Action = PutFieldl
  182. We do this for each field in the database table.
  183. When we are finished we UPDATE the record in the
  184. database table ---> DataTable.Action = UpdateRecordd
  185. Address"
  186. State"
  187. Phone"
  188. UpdateButton_Click
  189. DisplayError
  190. Here we show how to build a general purpose error routine for the DataTablee
  191. it is not complete but gives you the basic idea of how to build such a routine..
  192. For a listting of all DataTable error codes see the Working Model documentation.
  193. Drive not ready!
  194. Directory not found!
  195. File is busy!"
  196. File is Locked!"
  197. File not Found!"
  198.  Record not Found!
  199. End of Table!"
  200. Start of Table!"
  201. Unknown Error!
  202. CustomerName_LostFocus
  203. This code demonstrates how to search a database on a specific key.
  204. When you leave this field, this lost focus subroutine is executed.
  205. The value in the CustomerName.Text is then searched for in the database table.
  206. The database field searched is "Name" (The only key field in this example).t
  207. If the search is successfull the record is displayed on the form. If the searchh
  208. fails an error message is displayed, the form is cleared (with the typed in value)
  209. replaced in the CustomerName.Text expecting to get a new customer's information.
  210. Temporary variable to hold Customer's name.d
  211. The first and only field in PRIMARY index 
  212. The first and only field of the keyl
  213. The value to search for
  214. Submit the search criteria
  215. Perform the search
  216. If an errorh
  217. Display the error 
  218. Assume new customer, temp store for new customer name 
  219. Clear the form
  220. Place the new customer name back in the form
  221. Now let the user type in the new infoa
  222. Search was successfull
  223. Fill in the form with customer infot
  224.